<!DOCTYPE html>
<html height100 xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta th:replace="authority/dynamic/common/edit/head"/>
    <style>
        .zsa-custom-checkbox-container {
            margin-left: 30px !important;
        }

        .zsa-cron-input-inline {
            width: calc(100% - 180px) !important;
            -webkit-width: calc(100% - 180px) !important;
            -moz-width: calc(100% - 180px) !important;
        }

        .zsa-cron-exec-time-inline {
            padding-left: 25px;
            min-height: 30px;
            width: calc(100% - 245px) !important;
            -webkit-width: calc(100% - 245px) !important;
            -moz-width: calc(100% - 245px) !important;
        }
    </style>
</head>

<body class="childrenBody" padding10>
<form class="layui-form layui-form-pane" lay-filter="form-time-task-cron" onsubmit="return false;">
    <input type="hidden" name="id" value="">
    <div class="layui-form-item">
        <label for="D_name" class="layui-form-label"><span class="x-red">*</span>名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="D_name" name="name" lay-verify="required"
                   placeholder="名称" autocomplete="off" value="">
        </div>
        <div class="my-notes">
            <div class="layui-elip layui-text content">
                简单描述作用，方便查询/预览
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="zsa-tab-sec layui-this">秒</li>
                <li class="zsa-tab-minute">分钟</li>
                <li class="zsa-tab-hour">小时</li>
                <li class="zsa-tab-day">日</li>
                <li class="zsa-tab-month">月</li>
                <li class="zsa-tab-week">周</li>
                <li class="zsa-tab-year">年</li>
            </ul>
            <div class="layui-tab-content">
                <div data-zsa-item-unit="sec" class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <input type="radio" name="sec" value="*" lay-filter="type-radio" checked title="每秒">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="sec" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="s" autocomplete="off" value="1"
                                       data-zsa-default="1" data-zsa-range="1-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="s" autocomplete="off" value="1"
                                       data-zsa-default="1" data-zsa-range="1-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">秒</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="sec" lay-filter="type-radio" value="loop" title="循环">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="s" autocomplete="off" value="0"
                                       data-zsa-default="0" data-zsa-range="0-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">秒开始，每</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="s" autocomplete="off" value="1"
                                       data-zsa-default="1" data-zsa-range="1-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">秒执行一次</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width: 100px;">
                            <input type="radio" name="sec" lay-filter="type-radio" value="custom" title="自定义">
                        </div>
                        <div class="layui-input-block zsa-custom-checkbox-container" id="custom-sec">
                        </div>
                    </div>
                </div>
                <div data-zsa-item-unit="minute" class="layui-tab-item">
                    <div class="layui-form-item">
                        <input type="radio" name="minute" lay-filter="type-radio" value="*" checked title="每分钟">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="minute" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="m" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="m" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">分钟</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="minute" lay-filter="type-radio" value="loop" title="循环">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="m" autocomplete="off"
                                       value="0" data-zsa-default="0" data-zsa-range="0-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">分钟开始，每</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="m" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-59" class="layui-input">
                            </div>
                            <div class="layui-form-mid">分钟执行一次</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width: 100px;">
                            <input type="radio" name="minute" lay-filter="type-radio" value="custom" title="自定义">
                        </div>
                        <div class="layui-input-block zsa-custom-checkbox-container" id="custom-minute">
                        </div>
                    </div>
                </div>
                <div data-zsa-item-unit="hour" class="layui-tab-item">
                    <div class="layui-form-item">
                        <input type="radio" name="hour" value="*" lay-filter="type-radio" checked title="每小时">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="hour" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="h" autocomplete="off"
                                       value="0" data-zsa-default="0" data-zsa-range="0-23" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="h" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="0-23" class="layui-input">
                            </div>
                            <div class="layui-form-mid">小时</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="hour" lay-filter="type-radio" value="loop" title="循环">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="h" autocomplete="off"
                                       value="0" data-zsa-default="0" data-zsa-range="0-23" class="layui-input">
                            </div>
                            <div class="layui-form-mid">小时开始，每</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="h" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="0-23" class="layui-input">
                            </div>
                            <div class="layui-form-mid">小时执行一次</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width: 100px;">
                            <input type="radio" name="hour" lay-filter="type-radio" value="custom" title="自定义">
                        </div>
                        <div class="layui-input-block zsa-custom-checkbox-container" id="custom-hour">
                        </div>
                    </div>
                </div>
                <div data-zsa-item-unit="day" class="layui-tab-item">
                    <div class="layui-form-item">
                        <input type="radio" name="day" value="*" lay-filter="type-radio" checked title="每日">
                    </div>
                    <div class="layui-form-item">
                        <input type="radio" name="day" value="?" lay-filter="type-radio" title="不指定">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="day" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="d" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-31" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="d" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-31" class="layui-input">
                            </div>
                            <div class="layui-form-mid">号</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="day" lay-filter="type-radio" value="loop" title="循环">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="d" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-31" class="layui-input">
                            </div>
                            <div class="layui-form-mid">号开始，每</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="d" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-31" class="layui-input">
                            </div>
                            <div class="layui-form-mid">天执行一次</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 10px;">
                                <input type="radio" name="day" lay-filter="type-radio" value="newly" title="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">每月</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="d" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-31" class="layui-input">
                            </div>
                            <div class="layui-form-mid">号最近的那个工作日</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <input type="radio" name="day" value="L" lay-filter="type-radio" title=" 本月最后一天">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width: 100px;">
                            <input type="radio" name="day" value="custom" lay-filter="type-radio" title="自定义">
                        </div>
                        <div class="layui-input-block zsa-custom-checkbox-container" id="custom-day">
                        </div>
                    </div>
                </div>
                <div data-zsa-item-unit="month" class="layui-tab-item">
                    <div class="layui-form-item">
                        <input type="radio" name="month" value="*" lay-filter="type-radio" checked title="每月">
                    </div>
                    <div class="layui-form-item">
                        <input type="radio" name="month" lay-filter="type-radio" value="?" title="不指定">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="month" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="M" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-12" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="M" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-12" class="layui-input">
                            </div>
                            <div class="layui-form-mid">月</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="month" lay-filter="type-radio" value="loop" title="循环">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="M" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-12" class="layui-input">
                            </div>
                            <div class="layui-form-mid">月开始，每</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="M" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-12" class="layui-input">
                            </div>
                            <div class="layui-form-mid">个月执行一次</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width: 100px;">
                            <input type="radio" name="month" lay-filter="type-radio" value="custom" title="自定义">
                        </div>
                        <div class="layui-input-block zsa-custom-checkbox-container" id="custom-month">
                        </div>
                    </div>
                </div>
                <div data-zsa-item-unit="week" class="layui-tab-item">
                    <p class="layui-text">注：日 设置为 ’不指定‘，月 设置为 ‘每月’，1 星期天，2 星期一，3 星期二 以此内推</p>
                    <div class="layui-form-item">
                        <input type="radio" name="week" lay-filter="type-radio" value="*" title="每周">
                    </div>
                    <div class="layui-form-item">
                        <input type="radio" name="week" lay-filter="type-radio" value="?" checked title="不指定">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="week" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从星期</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="W" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-7" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="W" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-7" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="week" lay-filter="type-radio" value="loop" title="循环">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="W" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-7" class="layui-input">
                            </div>
                            <div class="layui-form-mid">周开始，每</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="W" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-7" class="layui-input">
                            </div>
                            <div class="layui-form-mid">天执行一次</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="week" lay-filter="type-radio" value="appoint" title="指定">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从第</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="W" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-4" class="layui-input">
                            </div>
                            <div class="layui-form-mid">周的星期</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="W" autocomplete="off"
                                       value="1" data-zsa-default="1" data-zsa-range="1-7" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width: 100px;">
                            <input type="radio" name="week" lay-filter="type-radio" value="custom" title="自定义">
                        </div>
                        <div class="layui-input-block zsa-custom-checkbox-container" id="custom-week">
                        </div>
                    </div>
                </div>
                <div data-zsa-item-unit="year" class="layui-tab-item">
                    <div class="layui-form-item">
                        <input type="radio" name="year" lay-filter="type-radio" value="" checked title="不指定">
                    </div>
                    <div class="layui-form-item">
                        <input type="radio" name="year" lay-filter="type-radio" value="*" title="每年">
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="radio" name="year" lay-filter="type-radio" value="range" title="周期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid">从</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="start" placeholder="y" autocomplete="off"
                                       value="2019" data-zsa-default="2019" data-zsa-range="2013-3000"
                                       class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="number" name="end" placeholder="y" autocomplete="off"
                                       value="2019" data-zsa-default="2019" data-zsa-range="2013-3000"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <fieldset class="layui-elem-field" style="min-width: 100%;min-width: inherit;">
                    <legend>表达式</legend>
                    <div class="layui-field-box">
                        <div class="layui-form-item" style="margin-top: 7px;">
                            <table id="cron-table" lay-filter="cron-table" class="layui-hide"></table>
                        </div>
                        <div class="layui-form-item">
                            <label for="D_cron" class="layui-form-label"><span class="x-red">*</span>表达式</label>
                            <div class="layui-block">
                                <div class="layui-input-inline zsa-cron-input-inline">
                                    <input type="text" class="layui-input" name="cron" lay-verify="required"
                                           id="D_cron" placeholder="CRON表达式" autocomplete="off">
                                </div>
                                <div class="layui-input-inline" style="width: 50px">
                                    <button class="layui-btn layui-btn-sm cron-inverse-analysis">反解析</button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item" style="margin-bottom: 0;">
                            <label class="layui-form-label">最近运行</label>
                            <div class="layui-block">
                                <div class="layui-input-inline layui-text zsa-cron-exec-time-inline recent-exec-time-list">

                                </div>
                                <div class="layui-input-inline" style="width: 50px">
                                    <button class="layui-btn layui-btn-sm obtain-recent-exec-time">获取运行时间</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>
    </div>

    <div class="layui-row layui-form-item" pane>
        <label for="D_state" class="layui-form-label"><span class="x-red">*</span>是否有效</label>
        <div class="layui-input-block">
            <input type="checkbox" name="state" id="D_state" lay-skin="switch" checked lay-text="正常|无效">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入备注内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" style="float: right" id="my-submit" lay-filter="submit" lay-submit>保存信息</button>
    </div>
</form>

<script th:replace="authority/dynamic/common/edit/footer"></script>
<script>
    layui.extend({
        initTable: 'initTable/initTable'
    });
    layui.use(['form', 'initTable', 'lutil', 'element'], function () {
        var form = layui.form,
            lutil = layui.lutil,
            table = layui.table,
            element = layui.element;

        generateCheckbox('#custom-sec', "custom-sec", 0, 59);
        generateCheckbox('#custom-minute', "custom-minute", 0, 59);
        generateCheckbox('#custom-hour', "custom-hour", 0, 23);
        generateCheckbox('#custom-day', "custom-day", 1, 31, false);
        generateCheckbox('#custom-month', "custom-month", 1, 12, false);
        generateCheckbox('#custom-week', "custom-week", 1, 7, false);
        form.render('checkbox', 'form-time-task-cron');

        var cron_data = [{sec: '*', minute: '*', hour: '*', day: '*', month: '*', week: '?', year: ''}];
        var cron_table = table.render({
            elem: '#cron-table',
            data: cron_data,
            title: '任务表',
            page: false,
            cellMinWidth: '80',
            cols: [
                [//标题栏
                    {field: 'sec', title: '秒'},
                    {field: 'minute', title: '分'},
                    {field: 'hour', title: '小时'},
                    {field: 'day', title: '日'},
                    {field: 'month', title: '月'},
                    {field: 'week', title: '周'},
                    {field: 'year', title: '年'}
                ]
            ]
        });
        $('#D_cron').val(analysisCronData(cron_data[0]));

        function analysisCronData(data) {
            var cron = data['sec'] + ' ' + data['minute'] + ' ' + data['hour'] + ' ' + data['day'] + ' ' + data['month'] + ' ' + data['week'];
            return data['year'] === '' || data['year'] === undefined ? cron : cron + ' ' + data['year'];
        }

        function generateCheckbox(parentElem, name, minValue, maxValue, twoPlace) {
            twoPlace = twoPlace === undefined ? true : twoPlace;
            for (var i = minValue; i <= maxValue; i++) {
                var val = ((twoPlace && i < 10 ? '0' : '') + i);
                $(parentElem).append($('<input type="checkbox" name="' + name + '" title="' + val + '" value="' + val + '" lay-skin="primary" lay-filter="value-checkbox">'));
            }
        }

        form.on('radio(type-radio)', function (data) {
            var parentItemElem = $(data.elem).closest('.layui-form-item');
            switch (data.value) {
                case '*': // 每*
                case '': // 年 不指定
                case '?': // 不指定
                case 'L': // 天 每月最后
                    cron_data[0][obtainCurrentUnit(data.elem)] = data.value;
                    break;
                case 'range': //范围/周期
                    var start = parentItemElem.find('input[type=number][name=start]').val()
                        , end = parentItemElem.find('input[type=number][name=end]').val();
                    cron_data[0][obtainCurrentUnit(data.elem)] = start + '-' + end;
                    break;
                case 'loop'://循环
                    var start = parentItemElem.find('input[type=number][name=start]').val()
                        , end = parentItemElem.find('input[type=number][name=end]').val();
                    cron_data[0][obtainCurrentUnit(data.elem)] = start + '/' + end;
                    break;
                case 'appoint'://指定
                    var start = parentItemElem.find('input[type=number][name=start]').val()
                        , end = parentItemElem.find('input[type=number][name=end]').val();
                    cron_data[0][obtainCurrentUnit(data.elem)] = start + '#' + end;
                    break;
                case 'newly'://最近
                    var start = parentItemElem.find('input[type=number][name=start]').val();
                    cron_data[0][obtainCurrentUnit(data.elem)] = start + 'W';
                    break;
                case 'custom'://自定义
                    var value = [];
                    parentItemElem.find('input[type=checkbox]:checked').each(function (i, e) {
                        value.push(parseInt(this.value));
                    });
                    if (value.length === 0)
                        return parentItemElem.find('input[type=checkbox] + .layui-form-checkbox').eq(0).click();
                    cron_data[0][obtainCurrentUnit(data.elem)] = value.join(',');
                    break;
            }
            cron_table.refresh();
            $('#D_cron').val(analysisCronData(cron_data[0]));
            $('.recent-exec-time-list').empty();
        });

        $('.cron-inverse-analysis').click(function (e) {
            var cron = $('#D_cron').val();
            if (!cronValidate(cron)) return lutil.error_alert("表达式无效"), false;
            var crons = cron.split(' ');
            cron_data[0] = {
                sec: crons[0],
                minute: crons[1],
                hour: crons[2],
                day: crons[3],
                month: crons[4],
                week: crons[5],
                year: crons[6] ? crons[6] : ''
            };
            $.each(cron_data[0], function (k, v) {
                var tabItemElem = $('div[data-zsa-item-unit="' + k + '"].layui-tab-item');
                if (v === '' || v === '*' || v === '?' || v === 'L')
                    return tabItemElem.find('input[type=radio][lay-filter="type-radio"][value="' + v + '"] + .layui-form-radio').click(), true;
                if (v.indexOf('-') > 0) {
                    var split = v.split('-');
                    var radioElem = tabItemElem.find('input[type=radio][lay-filter="type-radio"][value="range"]'),
                        formItemElem = radioElem.closest('.layui-form-item');
                    formItemElem.find('input[type=number][name=start]').val(split[0])
                        , formItemElem.find('input[type=number][name=end]').val(split[1]);
                    radioElem.find('+ .layui-form-radio').click();
                    return true;
                }
                if (v.indexOf('/') > 0) {
                    var split = v.split('/');
                    var radioElem = tabItemElem.find('input[type=radio][lay-filter="type-radio"][value="loop"]'),
                        formItemElem = radioElem.closest('.layui-form-item');
                    formItemElem.find('input[type=number][name=start]').val(split[0])
                        , formItemElem.find('input[type=number][name=end]').val(split[1]);
                    radioElem.find('+ .layui-form-radio').click();
                    return true;
                }
                if (v.indexOf('#') > 0) {
                    var split = v.split('#');
                    var radioElem = tabItemElem.find('input[type=radio][lay-filter="type-radio"][value="appoint"]'),
                        formItemElem = radioElem.closest('.layui-form-item');
                    formItemElem.find('input[type=number][name=start]').val(split[0])
                        , formItemElem.find('input[type=number][name=end]').val(split[1]);
                    radioElem.find('+ .layui-form-radio').click();
                    return true;
                }
                if (v.indexOf('W') > 0) {
                    var radioElem = tabItemElem.find('input[type=radio][lay-filter="type-radio"][value="newly"]'),
                        formItemElem = radioElem.closest('.layui-form-item');
                    formItemElem.find('input[type=number][name=start]').val(v);
                    radioElem.find('+ .layui-form-radio').click();
                    return true;
                }
                var radioElem = tabItemElem.find('input[type=radio][lay-filter="type-radio"][value="custom"]'),
                    formItemElem = radioElem.closest('.layui-form-item');
                formItemElem.find('.zsa-custom-checkbox-container input[type="checkbox"]').each(function (i1, e1) {
                    var that = this;
                    $.each(v.split(','), function (i, e) {
                        if (parseInt(that.value) === parseInt(e)) return that.checked = true, false;
                    })
                });
                radioElem.find('+ .layui-form-radio').click();
            });
            form.render('checkbox', 'form-time-task-cron');
        });

        $('.obtain-recent-exec-time').click(function (e) {
            $('.recent-exec-time-list').empty();
            var loading = layer.load(2, {shade: [0.3, '#eee']});
            ajaxRequestByCsrf(content_path + 'authority/timed_task_cron/recent_exec_time.do',
                {cron: $("#D_cron").val(), num: 5},
                function (res) {
                    if (res.data) {
                        $.each(res.data, function (i, e) {
                            $('.recent-exec-time-list').append("<p>" + e + "</p>");
                        });
                    } else {
                        $('.recent-exec-time-list').append("<p>无效的表达式</p>");
                    }
                }, null, function () {
                    layer.close(loading);
                })
        });

        function obtainCurrentUnit(elem) {
            return elem ? $(elem).closest('.layui-tab-item').data('zsa-item-unit') : '';
        }

        function cronValidate(cron) {
            var cronIsValid = false, loading = layer.load(2, {shade: [0.3, '#eee']});
            ajaxRequestByCsrf(content_path + 'authority/timed_task_cron/validate.do', {cron: cron}, function (res) {
                if (res.data === 'true' || res.data === true) cronIsValid = true;
            }, null, function () {
                layer.close(loading);
            }, {async: false});
            return cronIsValid;
        }

        $('.layui-tab-item input[type=number]').on('focus input propertychange change', function (e) {
            var range = $(this).data('zsa-range'), ranges = range ? range.split('-') : [0, 0];
            if ((e.type === 'change' && this.value === '') || parseInt(ranges[0]) > parseInt(this.value) || parseInt(this.value) > parseInt(ranges[1]))
                this.value = $(this).data('zsa-default');
            $(this).closest('.layui-form-item').find('input[type="radio"][lay-filter="type-radio"] + .layui-form-radio').click();
        });

        form.on('checkbox(value-checkbox)', function (data) {
            $(data.elem).closest('.layui-form-item').find('input[type="radio"][lay-filter="type-radio"] + .layui-form-radio').click();
        });

        form.on('submit(submit)', function (formData) {
            if (!cronValidate(analysisCronData(cron_data[0]))) return lutil.error_alert("请填写有效的表达式"), false;
            var loding = layer.load(2, {shade: [0.3, '#eee']});
            ajaxRequestByCsrf(content_path + 'authority/timed_task_cron/save.do', $.extend(formData.field, {
                state: formData.field['state'] ? 1 : 0
            }), function (res) {
                lutil.success_msg(res.message);
                var index = window.name && parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            }, null, function (res) {
                layer.close(loding);
            });
            return false;
        });


        if ("[[${id}]]" !== '') {
            var loading = layer.load(2, {shade: [0.3, '#eee']});
            ajaxRequestByCsrf(content_path + 'authority/timed_task_cron/detail/[[${id}]].do', {}, function (res) {
                form.val("form-time-task-cron", $.extend(res.data, {state: res.data['state'] === 1}));
                $('.cron-inverse-analysis').click();
            }, null, function (res) {
                layer.close(loading);
            });
        }
    })
</script>
</body>
</html>